package com.zycfc.zsf.boot.job.core;

import com.dangdang.ddframe.job.api.*;
import com.dangdang.ddframe.job.reg.base.*;
import com.dangdang.ddframe.job.lite.config.*;
import com.dangdang.ddframe.job.lite.api.listener.*;
import com.dangdang.ddframe.job.event.*;
import com.dangdang.ddframe.job.lite.spring.job.util.*;
import com.google.common.base.*;

public class ZsfSpringJobScheduler extends ZsfJobScheduler
{
    private final ElasticJob elasticJob;
    
    public ZsfSpringJobScheduler(final ElasticJob elasticJob, final CoordinatorRegistryCenter regCenter, final LiteJobConfiguration jobConfig, final ElasticJobListener... elasticJobListeners) {
        super(regCenter, jobConfig, getTargetElasticJobListeners(elasticJobListeners));
        this.elasticJob = elasticJob;
    }
    
    public ZsfSpringJobScheduler(final ElasticJob elasticJob, final CoordinatorRegistryCenter regCenter, final LiteJobConfiguration jobConfig, final JobEventConfiguration jobEventConfig, final ElasticJobListener... elasticJobListeners) {
        super(regCenter, jobConfig, jobEventConfig, getTargetElasticJobListeners(elasticJobListeners));
        this.elasticJob = elasticJob;
    }
    
    private static ElasticJobListener[] getTargetElasticJobListeners(final ElasticJobListener[] elasticJobListeners) {
        final ElasticJobListener[] result = new ElasticJobListener[elasticJobListeners.length];
        for (int i = 0; i < elasticJobListeners.length; ++i) {
            result[i] = (ElasticJobListener)AopTargetUtils.getTarget((Object)elasticJobListeners[i]);
        }
        return result;
    }
    
    @Override
    protected Optional<ElasticJob> createElasticJobInstance() {
        return (Optional<ElasticJob>)Optional.fromNullable((Object)this.elasticJob);
    }
}
